package com.lyf.scm.plan.domain.repository;

import com.github.pagehelper.PageInfo;
import com.lyf.scm.common.enums.SalesPlanDirectlyDifferinEnum;
import com.lyf.scm.common.util.AdvancedSearchUtil;
import com.lyf.scm.plan.api.dto.EChartsDTO;
import com.lyf.scm.plan.api.dto.SalePlanDirectlyDifferinDTO;
import com.lyf.scm.plan.api.dto.SalePlanDirectlyDifferinInfoDTO;
import com.lyf.scm.plan.domain.convertor.SalePlanDirectlyDifferinSelectConvertor;
import com.lyf.scm.plan.insfrastructure.db.dataobject.SalesPlanSelectDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyDifferinInDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyDifferinUpDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyUpDO;
import com.lyf.scm.plan.insfrastructure.db.mapper.SalePlanDirectlyDifferinMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.groupingBy;

/**
 * 直营预测计划_目标与销售计划差异
 *
 * @author wangchlei
 * @date 2020/08/05
 */
@Service
public class SalePlanDirectlyDifferinRepository {
    @Resource
    private SalePlanDirectlyDifferinMapper salePlanDirectlyDifferinMapper;

    /**
     * 按条件查询直营预测计划_目标与销售计划差异(周)
     *
     * @param salesPlanSelectDO
     * @return {@link PageInfo<SalePlanDirectlyDifferinInfoDTO>}
     **/
    public List<SalePlanDirectlyDifferinInfoDTO> listByCycles(SalesPlanSelectDO salesPlanSelectDO) {
        return salePlanDirectlyDifferinMapper.listByCycles(salesPlanSelectDO);
    }

    /**
     * 图表数据接口
     *
     * @param salesPlanSelectDO
     * @return {@link EChartsDTO}
     **/
    public List<SalePlanDirectlyDifferinInfoDTO> eChartsData(SalesPlanSelectDO salesPlanSelectDO) {
        return salePlanDirectlyDifferinMapper.listEChartsDataByCycles(salesPlanSelectDO);
    }

    /**
     * 导出所有查询数据
     *
     * @param salesPlanSelectDO
     * @return {@link List<SalePlanDirectlyDifferinInfoDTO>}
     **/
    public List<SalePlanDirectlyDifferinInfoDTO> searchedDataExport(SalesPlanSelectDO salesPlanSelectDO) {
        return salePlanDirectlyDifferinMapper.listByCycles(salesPlanSelectDO);
    }

    /**
     * 大数据批量新增
     *
     * @param directlyDifferinInDOs
     * @return void
     **/
    public void batchInsert(List<DirectlyDifferinInDO> directlyDifferinInDOs) {
        salePlanDirectlyDifferinMapper.batchInsert(directlyDifferinInDOs);
    }

    public void batchDeleteByStartDate(String storeCode, Date weekStartDate) {
        salePlanDirectlyDifferinMapper.batchDeleteByStartDate(storeCode, weekStartDate);
    }

    public List<DirectlyDifferinUpDO> listUpByStoreAndDate(String code, Date startDate, Date endDate) {
        return salePlanDirectlyDifferinMapper.listUpByStoreAndDate(code, startDate, endDate);
    }

    public void rmByIds(List<Long> ids) {
        salePlanDirectlyDifferinMapper.rmByIds(ids);
    }

    public void upByIds(List<DirectlyDifferinUpDO> list) {
        salePlanDirectlyDifferinMapper.upByIds(list);
    }

    public void delete(String opSign){
        salePlanDirectlyDifferinMapper.delete(opSign);
    }

    public void deleteByOpSign(String opSign) {
        salePlanDirectlyDifferinMapper.deleteByOpSign(opSign);
    }
}
